/**
 * @file   1093.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Mon Apr 19 18:08:40 2021
 * 
 * @brief  PAT 1093:counting PATs
 * 
 * 
 */
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    int Pnum=0;
    int Tnum=0;
    vector<int> PSet;
    vector<int> TSet;
    for(int i=0;i<s.length();i++){
	if(s[i]=='P'){
	    Pnum++;
	}
	if(s[i]=='A'){
	    PSet.push_back(Pnum);
	}
    }
    for(int i=s.length()-1;i>=0;i--){
	if(s[i]=='T'){
	    Tnum++;
	}
	if(s[i]=='A'){
	    TSet.push_back(Tnum);
	}
    }
    int sum=0;
    for(int i=0;i<PSet.size();i++){
	sum=sum+PSet[i]*TSet[PSet.size()-1-i];
	sum=sum%1000000007;
    }
    cout<<sum<<endl;
}
